package redora.rdo.client;

import java.util.LinkedHashMap;

import redora.rdo.client.data.DataPanel;
import redora.rdo.client.model.ModelPanel;
import redora.rdo.client.tagging.RedOrangePanel;
import redora.rdo.client.upgrade.UpgradePanel;
import redora.rdo.configuration.client.DataSourceFactory;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.ui.Hyperlink;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;

public class ShowcasePanel extends VLayout {
	HLayout linkPanel = new HLayout();
	Layout mainPanel = new Layout();

	public ShowcasePanel(final DataSourceFactory factory) {
		this.setWidth100();
		this.setHeight100();

		Hyperlink modelLink = new Hyperlink("Model", "");
		modelLink.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent arg0) {
				mainPanel.removeMembers(mainPanel.getChildren());
				mainPanel.addMember(new ModelPanel());
			}
		});
		Hyperlink dataLink = new Hyperlink("Data", "");
		dataLink.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent arg0) {
				mainPanel.removeMembers(mainPanel.getChildren());
				mainPanel.addMember(new DataPanel(factory));
			}
		});
		Hyperlink upgradeLink = new Hyperlink("Upgrade", "");
		upgradeLink.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent arg0) {
				mainPanel.removeMembers(mainPanel.getChildren());
				mainPanel.addMember(new UpgradePanel());
			}
		});
		Hyperlink taggingLink = new Hyperlink("Tagging", "");
		taggingLink.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent arg0) {
				mainPanel.removeMembers(mainPanel.getChildren());
				mainPanel.addMember(new RedOrangePanel());
			}
		});
		linkPanel.addMember(modelLink);
		linkPanel.addMember(dataLink);
		linkPanel.addMember(upgradeLink);
		linkPanel.addMember(taggingLink);

		SelectItem selectItem = new SelectItem();
		selectItem.setHeight(21);
		selectItem.setWidth(130);
		LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
		valueMap.put("Enterprise", "Enterprise");
		valueMap.put("BlackOps", "BlackOps");
		valueMap.put("Fleet", "Fleet");
		valueMap.put("SilverWave", "SilverWave");
		valueMap.put("TreeFrog", "TreeFrog");

		selectItem.setValueMap(valueMap);

		String currentSkin = Cookies.getCookie("skin_name");
		if (currentSkin == null) {
			currentSkin = "Enterprise";
		}
		selectItem.setDefaultValue(currentSkin);
		selectItem.setShowTitle(false);
		selectItem.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				Cookies.setCookie("skin_name", (String) event.getValue());
				com.google.gwt.user.client.Window.Location.reload();
			}
		});

		DynamicForm form = new DynamicForm();
		form.setPadding(0);
		form.setMargin(0);
		form.setCellPadding(1);
		form.setNumCols(1);
		form.setFields(selectItem);
		form.setAlign(Alignment.RIGHT);
		linkPanel.addMember(form);

		linkPanel.setWidth100();
		linkPanel.setHeight("2%");
		this.addMember(linkPanel);
		mainPanel.setWidth100();
		mainPanel.setHeight100();
		this.addMember(mainPanel);
		this.draw();
	}

}
